<template>
    <view style="padding: 20rpx">
        <form class="form" @submit="submit">
            <view class="form-item">
                <input
                    placeholder="请输入通道标题名称"
                    name="channelTitle"
                    v-model="channelTitle"
                    class="form-control"
                    style="background: #f6f6f6"
                    @input="bindKeyInput"
                    @confirm="submit"
                />
            </view>
            <view class="form-item">
                <button class="block radius-btn" type="primary" form-type="submit">确认</button>
            </view>
        </form>
    </view>
</template>

<script>
export default {
    data() {
        return {
            token: '',
            channelTitle: ''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {
        console.log('=== ChannelTitle:onLoad:', options);
		this.token =  options.token
		this.getChannelTitle();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        // 获取通道标题
        getChannelTitle() {
            uni.showLoading();
            let token = this.token;
            let data = {
                Name: 'ChannelTitle'
            };
            getApp().globalData.api.getconfig(data, token, (result) => {
                uni.hideLoading({
                    success: (res) => {
                        this.channelTitle = result.ChannelTitle[0]
                    }
                });
            });
        },

        // 设置通道标题
        submit(ev) {
            uni.showLoading();
            let token = this.token;
            let data = {
                Name: 'ChannelTitle',
                ChannelTitle: [this.channelTitle]
            };
            getApp().globalData.api.setconfig(data, token, (result) => {
                uni.showToast({
                    title: '设置成功！',
                    success: (res) => {
                        uni.navigateBack({
                            delta: 1
                        });
                    }
                });
            });
        },

        bindKeyInput() {
            console.log('占位：函数 bindKeyInput 未声明');
        }
    }
};
</script>
<style></style>
